﻿Imports DTO
Imports System.Data.OleDb

Public Class PhieuNhapDAO
    Public Shared Function SelectPhieuNhapAll() As DataTable
        Dim sql As String = "select* from PHIEUNHAP"
        Dim dt As DataTable = DatabassProvider.ExcuQuery(sql)
        Return dt
    End Function

    Public Shared Function SelectPhieuNhapChiTietAll() As DataTable
        Dim sql As String = "select * from CHITIETPHIEU"
        Dim dt As DataTable = DatabassProvider.ExcuQuery(sql)
        Return dt
    End Function

    Public Shared Sub Insert(ByVal p As PhieuNhapDTO)
        Dim sql As String = "insert into CHITIETPHIEU(MaPhieuNhap,MaSach,SoLuongNhap) values(" & p.MaPhieuNhap & "," & p.MaSach & "," & p.SoLuong & ")"
        DatabassProvider.ExcuNonQuery(sql)
    End Sub

    Public Shared Sub Insertphieunhap(ByVal p As PhieuNhapDTO)
        Dim sql As String = "insert into PHIEUNHAP(NgayNhap) values('" & p.NgayNhap & "')"
        DatabassProvider.ExcuNonQuery(sql)
    End Sub

    Public Shared Function GetPhieuNhapByName(ByVal maphieunhap As Integer, ByVal masach As Integer) As PhieuNhapDTO
        Dim sql As String = "select * from CHITIETPHIEU where ((MaPhieuNhap=" & maphieunhap & ")AND(MaSach = " & masach & "))"
        Dim dt As DataTable = DatabassProvider.ExcuQuery(sql)
        If dt.Rows.Count = 0 Then
            Return Nothing
        Else
            Dim pn As New PhieuNhapDTO()
            pn.MaPhieuNhap = CInt(Fix(dt.Rows(0).ItemArray(0)))
            Return pn
        End If

    End Function
End Class
